// pages/index/labelDetail/labelDetail.js
const tools = require('../../../utils/tool')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    visit_num: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      headerInfo: options
    })
    this.getLabel()
  },
  getLabel() {
    tools.request('/api/applets/label', 'get', {
        name: this.data.headerInfo.name
      }, wx.getStorageSync('token'))
      .then(res => {
        console.log(res)
        if (res.data.status) {
          this.setData({
            related: res.data.list,
            visit_num: res.data.visit_num
          })
        }
      })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 获取热门更多
  getLabelMore(url, second_cate_id) {
    let getMore = tools.request(url, 'get', {
      name: headerInfo.name
    }, wx.getStorageSync('token'))
    getMore.then(res => {
        if (res.data.status) {
          let related = this.data.hot.concat(res.data.list)
          this.setData({
            related,
            next_page_url: res.data.list.next_page_url,
          })
        }
      })
      .catch(err => {
        wx.showToast({
          title: err.errMsg,
          icon: 'none'
        })
      })
  },
  onReachBottom: function () {
    if (this.data.next_page_url != null) {
      this.getLabelMore(this.data.next_page_url, second_cate_id)
    }
  },
})